import React, { memo, Component } from 'react'
import { getUserInfo, getClassInfo } from '@/api/user'
import BasicControl from '@/components/pageComponents/basicControl'
import { StudentInfo } from '../../utils/model'
import Comments from '@/components/pageComponents/comments'
import { Spin, Alert, message } from 'antd'
import Marquee from 'react-fast-marquee'
import '../../index.css'
// import { NotificationOutlined } from '@ant-design/icons';
class classIndex extends Component {
  static contextType = StudentInfo
  constructor(props) {
    super(props)
    this.state = {
      loading: true,
      userInfo: null, //用来存用户信息
      classInfo: null //用来存班级信息
    }
  }
  
  componentDidMount() {
    let timer = setInterval(()=>{
        let userInfo = this.context?.studentInfo
        if(userInfo) {
            clearInterval(timer)
            this.setState({
                userInfo
              })
        }
        if (userInfo?.classId) {
          let classInfo = this.context?.studentInfo?.classInfo
          this.setState({
            classInfo,
            loading: false
          })
        } else {
          message.warn('请前往个人中心选择班级哦～')
        }
    },500)
    
  }
  render() {
    let { userInfo, classInfo } = this.state
    return (
      <Spin spinning={this.state.loading} size="large">
        <div style={{ height: '100vh' }}>
          {classInfo?.announcement && (
            <Alert
              banner
              type="info"
              message={
                <Marquee pauseOnHover gradient={false}>
                  班级公告：{classInfo?.announcement}
                </Marquee>
              }
              closable
              style={{
                position: 'fixed',
                width: '60%',
                marginLeft: '20%',
                borderRadius: '16px',
                border: '1px solid #93bbff',
                marginTop: '10px',
                background: 'rgba(255,255,255,.5)',
                zIndex: 98
              }}
            />
          )}
          <div
            style={{
              display: 'flex'
            }}
          >
            {/* <BasicControl/> */}
            {userInfo?.classId && <Comments type={1} userInfo={userInfo} />}
          </div>
        </div>
      </Spin>
    )
  }
}
export default memo(classIndex)
